﻿@using Smartstore.Web.Models.Customers;

@model CustomerStockSubscriptionsModel

@{
    Assets.AppendTitleParts(T("PageTitle.BackInStockSubscriptions"));

    Layout = "_MyAccount";
    ViewBag.PageClassToken = "backinstock";
    ViewBag.PageTitle = T("Account.BackInStockSubscriptions").Value;
}

@if (Model.Subscriptions.Count == 0)
{
    <div class="alert alert-warning">
        @T("Account.BackInStockSubscriptions.NoSubscriptions")
    </div>
    return;
}

<div class="alert alert-success mb-0">
    @T("Account.BackInStockSubscriptions.Description")
</div>

<form asp-action="StockSubscriptions">
    <div id="stock-subscription-list" class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th style="width: 30px">
                        <input type="checkbox" id="select-all-stock-subscriptions" />
                    </th>
                    <th>
                        @T("Account.BackInStockSubscriptions.ProductColumn")
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Subscriptions)
                {
                    <tr>
                        <td style="width: 30px">
                            <input type="checkbox" name="biss@(item.Id)" class="rowcheckbox" />
                        </td>
                        <td sm-language-attributes-for="item.ProductName">
                            @Html.RouteLink(item.ProductName, "Product", new { SeName = item.SeName })
                        </td>
                    </tr>
                }
            </tbody>
        </table>

        @if (Model.TotalPages > 1)
        {
            <pagination sm-list-items="Model" sm-query-param="page" id="paginator" />
        }

        <div class="buttons">
            <button id="btn-stock-subscriptions-delete" type="submit" class="btn btn-danger btn-lg disabled" disabled>
                <span>@T("Account.BackInStockSubscriptions.DeleteSelected")</span>
            </button>
        </div>
    </div>
</form>

<script sm-target-zone="scripts" data-origin="stock-subscriptions">
    $(function () {
        $('#select-all-stock-subscriptions').on('click', function () {
            $('#stock-subscription-list .rowcheckbox').prop('checked', $(this).is(':checked')).trigger('change');
        });

        $(document).on('change', '#stock-subscription-list .rowcheckbox', function () {
            var numChkBoxes = $('#stock-subscription-list .rowcheckbox').length;
            var numChkBoxesChecked = $('#stock-subscription-list .rowcheckbox:checked').length;
            var buttons = $('#btn-stock-subscriptions-delete');

            $('#select-all-stock-subscriptions').prop('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);

            if (numChkBoxesChecked > 0) {
                buttons.prop('disabled', false).removeClass('disabled');
            }
            else {
                buttons.addClass('disabled').prop('disabled', true);
            }
        });
    });
</script>
